package com.cloudcc.mobile.weight;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudcc.cloudframe.ui.viewgroup.loadmore.LoadMoreContainer;
import com.cloudcc.cloudframe.ui.viewgroup.loadmore.LoadMoreUIHandler;
import com.cloudcc.mobile.R;

/**
 * @Description: 自定义的cloudcc加载更多的
 * @author wangzhiqiang
 * @date 2015-12-14 下午2:08:27
 * 
 */
public class LoadMoreCloudCCFooterView extends LinearLayout implements
		LoadMoreUIHandler {
	private TextView mTextView;
	private TextView mExplain;
	private ImageView mImageView;

	public LoadMoreCloudCCFooterView(Context context) {
		this(context, null);
	}

	public LoadMoreCloudCCFooterView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public LoadMoreCloudCCFooterView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		setupViews();
	}

	private void setupViews() {
		LayoutInflater.from(getContext()).inflate(
				R.layout.views_load_cloudcc_footer, this);
		mTextView = (TextView) findViewById(R.id.no_result_label);
		mImageView = (ImageView) findViewById(R.id.no_result_image);
		mExplain = (TextView) findViewById(R.id.explain);
	}

	@Override
	public void onLoading(LoadMoreContainer container) {
		mImageView.setVisibility(View.GONE);
		mExplain.setVisibility(View.GONE);
		mTextView.setText(R.string.cube_views_load_more_loading);
	}

	@Override
	public void onLoadFinish(LoadMoreContainer container, boolean empty,
			boolean hasMore) {
        if (!hasMore) {//如果没有更多
            setVisibility(VISIBLE);
            if (empty) {//空
            	mImageView.setVisibility(View.VISIBLE);
                mTextView.setText(R.string.cube_views_load_more_loaded_empty);
            } else {//到底了 没有更多了
            	mImageView.setVisibility(View.GONE);
                mTextView.setText(R.string.cube_views_load_more_loaded_no_more);
            }
        } else {//还有更多
            setVisibility(GONE);
        }
	}

	@Override
	public void onWaitToLoadMore(LoadMoreContainer container) {
        setVisibility(VISIBLE);
        mTextView.setText(R.string.cube_views_load_more_click_to_load_more);
	}

	@Override
	public void onLoadError(LoadMoreContainer container, int errorCode,
			String errorMessage) {
		setVisibility(VISIBLE);
		mTextView.setText(R.string.cube_views_load_more_error);
	}

}
